let app = getApp();
import { validListItem } from "/utils/commonMethod";
import { showToast } from "/utils/common";
import omsRequest from "/utils/omsRequest";
import { getDistributableList } from "/api/distributeAchievement";
Page({
  data: {
    userInfo: null,
    collectionListTitle: ['序号', '名称', '目标'],
    saleMonthTargetItem: {}, // merchant or visit or deposit 
    list: [],
    cityNameText: '', // 城市
    undistributedNum: 0, // 剩余待分配业绩
  },
  onLoad(option) {
    this.getDistributableList();
    this.setData({
      saleMonthTargetItem: option && JSON.parse(option.saleMonthTargetItem),
      userInfo: app.globalData.userInfo
    })
  },
  getDistributableList() {
    dd.showLoading({
      content: '加载中...'
    })
    omsRequest({
      url: getDistributableList
    }).then((res) => {
      if (res.success) {
        // console.log( [... new Set(res.voList.map(((item) => item.cityNameList)).join().split(","))],"res.voList.map(((item) => item.cityNameList))")
        this.setData({
          list: res.voList,
          cityNameText:[... new Set(res.voList.map(((item) => item.cityNameList)).join().split(","))].join()
        })
        dd.hideLoading()
      }
    })
  },
  onChangeList(list) {
    let total = 0; // 输入收款金额 总值
    list.forEach(item => {
      total += +item.total
    });
    this.setData({
      undistributedNum: (this.data.saleMonthTargetItem.total / 10000 - total).toFixed(4)
    })
  },
  onChangeVo(vo) {
    this.data.saleMonthTargetItem.distributableFlag = vo.distributableFlag
    this.setData({
      saleMonthTargetItem:  this.data.saleMonthTargetItem
    })
  }
});
